home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2405 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  56 lines

  1. Path: news.acns.nwu.edu!news    
  2. From: "Lorraine E. Long" <llong@nwu.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help with simple code
  5. Date: 21 Jan 1996 04:42:27 GMT
  6. Organization: Northwestern University, Evanston, IL, US
  7. Message-ID: <4dsg7j$lpu@news.acns.nwu.edu>
  8. References: <4dbak5$oij@ionews.io.org>
  9. NNTP-Posting-Host: aragorn232.nuts.nwu.edu
  10.  
  11. jgordon@io.org (John Gordon MacPherson) wrote:
  12. >
  13. > Can anyone tell me what's wrong with this piece of code? I lifted it
  14. > straight from a textbook.
  15. > Here's the code:
  16. > /* Calculating compound interest */
  17. > #include <stdio.h>
  18. > #include <math.h>
  19. > main()
  20. > {
  21. >     int year;
  22. >     double amount, principal = 1000, rate = 0.5;
  23. >     printf("%4s%21s\n", "Year", "Amount on deposit");
  24. >     for (year = 1; year <= 10; year++) {
  25. >         amount = principal * pow(1.0 + rate, year);
  26. >         printf("%4d%21.2f\n", year, amount);
  27. >     }
  28. >     return 0;
  29. > }
  30. > ______________________________________________________________
  31. > and here's the error:
  32. > In function `main':
  33. > undefined reference to `pow'
  34. > I don't understand. `pow' is a function, not a variable?
  35. > Can anyone tell me what's wrong?
  36. > I don't know if you've solved this problem yet.  If you have, I'd
  37. like to know how you did it.  I have a couple of thoughts:  
  38. The textbook I have always specifies a data type for the pow
  39. function, as well as for the abs function, e.g., 
  40.         principal * double pow(. . .);
  41.  
  42. Also, would it be useful to enclose the value to be raised to a power
  43. in parens?
  44.         principal * double pow((1+rate), year); 
  45.  
  46.